package src.entity;

import java.util.Random;
import java.util.List;

public class Zombie {
    private int x;
    private int y;
    private boolean alive;
    private int speed;
    private static final int HITBOX_WIDTH = 70;
    private static final int HITBOX_HEIGHT = 70;

    public Zombie(int x, int y) {
        this.x = x;
        this.y = y;
        this.alive = true;
        this.speed = 3;
    }

    public static void spawnZombie(List<Zombie> zombies) {
        Random r = new Random();
        zombies.add(new Zombie(2500, r.nextInt(400)));
    }

    public void move() {
        this.x -= speed;
    }

    public void hitbox(List<Bullet> bullets, List<Player> players) {
        for (Bullet b : bullets) {
            if (b.getX() > this.x && b.getX() < this.x + HITBOX_WIDTH 
                && b.getY() > this.y && b.getY() < this.y + HITBOX_HEIGHT) {
                this.alive = false;
                b.setAlive(false);
                players.get(b.getPlayerId() - 1).incrementScore();
            }
        }
    }

    // Getters
    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isDead() {
        return !alive;
    }

    public int getSpeed() {
        return speed;
    }

    // Setters
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setAlive(boolean alive) {
        this.alive = alive;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }
}
